(function() {
  "use strict";
  APP.Views.DialogAddUserGroupView = Backbone.View.extend({
    el: '#modal',
    events : {
      'submit #addUserGroupForm': 'add'
    },
    initialize: function(params) {
      this.parentView = params.parentView;
    },
    add: function(e) {
      e.preventDefault();
      var name = this.$('#dialogAddUserGroup-name');
      var nameEn = this.$('#dialogAddUserGroup-nameEn');
      if (name.val() == '' || nameEn.val() == '') {
        if (name.val() == '') {
          name.closest('div.form-group').addClass('has-error');
        }
        if (nameEn.val() == '') {
          nameEn.closest('div.form-group').addClass('has-error');
        }
        return;
      }
      var callback = {
        obj: this,
        name: 'addUserGroupSuccess'
      }
      APP.BeClient.addUserGroup(this.$('#dialogAddUserGroup-name').val(), this.$('#dialogAddUserGroup-nameEn').val(), callback, undefined, {preloaderHide: false});
      
    },
    addUserGroupSuccess: function() {
      this.$el.modal('hide');
      this.parentView.reload();
    },
    render: function() {
      this.$el.html(_.template($('#dialogAddUserGroupTemplate').html()));
      this.$el.modal();
      return this;
    }
  });
}());